﻿using System;
using System.Collections.Generic;
using System.Runtime.ConstrainedExecution;


namespace xiaohongshu
{
    class SOl2
    {
        public static int maxBlackNodes;
        public int BlackTree2(string colors, IList<IList<int>> adjList)
        {
            maxBlackNodes = 0;

            DFS(0, -1, colors, adjList); // 从节点0开始DFS遍历
            return maxBlackNodes;
        }
        static int DFS(int node, int parent, string colors, IList<IList<int>> adjList)
        {
            int blackNodes = colors[node] == 'B' ? 1 : 0;

            foreach (int child in adjList[node])
            {
                if (child != parent)
                {
                    int subtreeNodes = DFS(child, node, colors, adjList);
                    blackNodes += subtreeNodes;
                }
            }

            if (colors[node] == 'R')
            {
                maxBlackNodes = Math.Max(maxBlackNodes, blackNodes);
                return 0; // 删除红色节点，返回0
            }

            return blackNodes;
        }


        int blackNums = 0;
        public int BlackTree(string colors, IList<IList<int>> adjList)
        {

            int res = 0;
            for (int i = 0; i < adjList.Count; i++)
            {
                char col = colors[i];
                if (col == 'R')//分别计算去除每个红色的结果
                {
                    int blackNum = 0;
                    //遍历红色的所有临边,除了自己
                  
                    for (int j = 0; j < adjList[i].Count; j++)
                    {
                       
                            int node = adjList[i][j];
                        if (i  != node)
                        {
                            Console.WriteLine("当前节点" + node);

                            int cur = DFSTree(node, i, colors, adjList);
                            Console.WriteLine("当前联通块的黑色"+cur);
                            blackNum = Math.Max(blackNum, cur);
                        }
                        
                    }
                    Console.WriteLine("删除当前红色，联通块的黑色" + blackNum);
                    res = Math.Max(blackNum, res);
                }
                


            }



            return res;

        }
        //以root为起点的黑色

        public int DFSTree(int root, int parent, string colors, IList<IList<int>> adjList)//临边可能包括自己的父母，不能继续
        {

            IList<int> curEdges = adjList[root];
            int curBlackNums = 0;

            if (colors[root] == 'B')//当前节点的颜色
            {
                curBlackNums = 1;
            }

            for (int i = 0; i < curEdges.Count; i++)
            {

                if (curEdges[i] == parent) { continue; }//红色也会参加遍历。只是不计数

                int childBlackNums = DFSTree(curEdges[i], root, colors, adjList);
                curBlackNums += childBlackNums;
                blackNums = Math.Max(blackNums, curBlackNums);

            }
            return curBlackNums;


        }



    }
    class Program2
    {
        public static void Main2(string[] args)
        {
            string line;
            while ((line = Console.ReadLine()) != null)
            {

                string[] tokens = line.Split();
                int n = int.Parse(tokens[0]);
                line = Console.ReadLine();
                string colors = line;
                IList<IList<int>> adjList = new List<IList<int>>();
                for (int i = 0; i < n; i++)
                {
                    adjList.Add(new List<int>());
                }


                for (int i = 0; i < n - 1; i++)
                {
                    line = Console.ReadLine();
                    string[] edge = line.Split();

                    int u = int.Parse(edge[0])-1 ;
                    int v = int.Parse(edge[1])-1 ;
                    adjList[u].Add(v);
                    adjList[v].Add(u);
                }
                SOl2 sol = new SOl2();
                int res = sol.BlackTree(colors, adjList);
                Console.WriteLine(res);
            }
        }

    }
}

//10
//RRBBBBBBBB
//1 2
//1 3
//1 4
//1 5
//1 7
//2 8
//4 6
//4 10
//6 9